package au.edu.utas.yu_qiao_group.luckyman.ui.raffledetail;

import java.util.Arrays;
import java.util.List;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;
import au.edu.utas.yu_qiao_group.luckyman.db.raffles.RaffleDTO;
import au.edu.utas.yu_qiao_group.luckyman.utils.ArrayUtils;

public class RaffleDetailViewModel extends BaseObservable {
  private RaffleDTO mData;

  private int mSelectedPricePosition;

  public List<String> pricesLabels = Arrays.asList(new String[]{"A$5.00", "A$10.00", "A$50.00", "A$100.00", "A$500.00"});
  public List<Integer> pricesValues = Arrays.asList(new Integer[]{5, 10, 50, 100, 500});

  public RaffleDetailViewModel(RaffleDTO r) {
    mData = r;
  }

  public void cloneFrom(RaffleDetailViewModel vm) {
    setModel(vm.getModel());
    setSelectedPricePosition(ArrayUtils.indexOfIntegerList(pricesValues, vm.getModel().getMUnitPrice()));
  }

  @Bindable
  public String getName() {
    return mData.getMName();
  }

  public void setName(String name) {
    mData.setMName(name);
  }

  @Bindable
  public String getBrief() {
    return mData.getMDesc();
  }

  public void setBrief(String desc) {
//    System.out.print("set new desc: " + desc);
    mData.setMDesc(desc);
  }

  @Bindable
  public String getCover() { return mData.getMCover(); }

  public void setCover(String filename) {
    mData.setMCover(filename);
  }

  @Bindable
  public String getOrganizer() {
    return mData.getMOrganizer();
  }

  public void setOrganizer(String company) {
    mData.setMOrganizer(company);
  }

  @Bindable
  public int getTotalAmount() {
    return mData.getMTicketTotal();
  }

  public void setTotalAmount(int num) {
    mData.setMTicketTotal(num);
  }

  @Bindable
  public int getSingleLimit() {
    return mData.getMSingleLimit();
  }

  public void setSingleLimit(int num) {
    mData.setMSingleLimit(num);
  }

  @Bindable
  public int getPrize() {
    return mData.getMAwardPrice();
  }

  public void setPrize(int num) {
    mData.setMAwardPrice(num);
  }

  @Bindable
  public long getDrawTime() {
    return mData.getMDrawTime();
  }

  public void setDrawTime(long time) {
    mData.setMDrawTime(time);
  }

  @Bindable
  public int getIsMarginRaffle() {
    return mData.getMDrawMethod();
  }

  public void setIsMarginRaffle(int isMarginRaffle) {
    mData.setMDrawMethod(isMarginRaffle);
  }

  @Bindable
  public int getSelectedPricePosition() {
    return mSelectedPricePosition;
  }

  public void setSelectedPricePosition(int selectedItemPosition) {
    if (selectedItemPosition < 0 || selectedItemPosition > pricesValues.size() - 1) {
      selectedItemPosition = 0;
    }
    this.mSelectedPricePosition = selectedItemPosition;
    mData.setMUnitPrice(pricesValues.get(mSelectedPricePosition));
  }

  public void setModel(RaffleDTO r) {
    mData = r;
  }

  public RaffleDTO getModel() {
    return mData;
  }

  public int getSelectedPrice() {
    return pricesValues.get(mSelectedPricePosition);
  }

}
